$(function(){
	/**调用初始化方法*/
	queryRole();
});

function queryRole(){
	$(this).hide();
	$('#usertable').bootstrapTable('destroy');
	$('#usertable').bootstrapTable({
		method: 'get',
		url: '/GetAllBindUser/',
		cache: false,
		striped: true,
		pagination:true,
		pageSize:20,
		pageList: [5, 10, 20,50],
		pageNumber:1,
		sidePagination:'server',
		width:'600',
		columns: [
			{
				field: 'id',
				title: 'Item ID',
				align: 'right',
				valign: 'bottom',
				visible:false
			},{
				field: 'acount',
				title: '用户名称',
				align: 'center',
				formatter: turnAround,
				valign: 'middle'
			},{
				field: 'ctime',
				title: '用户创建时间',
				align: 'center',
				formatter: turnAround,
				valign: 'middle'
			},
			{
				field: 'operate',
				title: '操作',
				align: 'center',
				valign: 'middle',
				formatter: operateFormatter,
				events: operateEvents
			}]
	});
}
/**
 * table图标区
 */
function operateFormatter(value, row, index) {
	return [
		'<button class="updateUser" id="updateUser">修改密码</button>'
		].join('');
}
/**
 * 图标绑定点击事件
 */
window.operateEvents = {
		'click .updateUser': function (e, value, row, index) {
			isModify=1;
			$("#titleId").html("修改密码");
			$(".acount").val(decodeURI(row.acount,"utf-8"));
			$(".password").val(decodeURI("","utf-8"));
			$("#userIds").val(row.id);
			$("#show_div_user").show();
		}
};

function turnAround(value, row, index){
	return decodeURI(value,"utf-8"); 
}
/* 点击提交的事件  */
$("#addUser").click(function(){
    $(".show_div").hide();
    var data={};
    var pass=$(".password").val();
    data.pass = pass;
    var id = $("#userIds").val();
    if(id!=0 && id!=null){
    	data.id = id;
    }
    if(pass){
    	$(this).html('发送中...');
        $(this).css({"background":"#616161"});
        $.post("/UpdateBindUserPass/",data,function(data){
        	data = decodeURI(data);
	    	var data1 = $.parseJSON(data);
	    	alert(data1);
	    	alert(data1.state);
	    	if(data1.state == 1){
	    		window.location.reload();
	    		alert(data1.message);
	    	}else{
	    		$(".showList_submit").html('提交');
	    		$(".showList_submit").css({"background":"#438EB9"});
	    		alert(data1.message);
	    		$("#show_div_user").show();
	    	}
        });
    }else{
        alert("填写错误");
    }
});
